package com.doctor.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

/**
 * 
 * @author wangxuebin
 *
 * @date 2014年9月6日 下午10:16:43
 */
public class AuthenticateFilter implements Filter {
	private static final Logger LOGGER = Logger
			.getLogger(AuthenticateFilter.class);

	public void init(FilterConfig filterConfig) throws ServletException {
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {

		HttpServletRequest httpRequest = (HttpServletRequest) request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;

		String virtPath = httpRequest.getRequestURI();// 虚拟路径

		HttpSession session = httpRequest.getSession();
		LOGGER.info("sessionId=" + session.getId() + ",virtPath=" + virtPath);

		if (virtPath == null) {
			virtPath = "";
		}
		// if (virtPath.endsWith("login.htm")
		// || virtPath.endsWith("register.htm")
		// || virtPath.endsWith("checkForUpdate.htm")
		// || virtPath.endsWith("sendClientVerificationCode.htm")
		// || virtPath.endsWith("resetPassword.htm")
		// || virtPath.endsWith("queryLocation.htm")
		// || virtPath.endsWith("loadActivationStatus.htm")) {// 登录、验证loginId,
		// // 注册不用过滤
		chain.doFilter(request, response);
		// } else {
		// if (session.getAttribute("user") == null) {
		// httpResponse.setStatus(401);// 未登录
		// } else {
		// chain.doFilter(request, response);
		// }
		// }
	}

	public void destroy() {
	}
}
